<template>
  <!--  试验计划  -->
  <div class="app-container">
    <el-card class="dis">
      <el-form :inline="true" :model="formInline" class="formHeight">
        <el-form-item label="">
          <el-input v-model="formInline.keyword" size="mini" placeholder="关键字：计划标题" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="mini" @click="search">查询</el-button>
          <el-button type="primary" size="mini" @click="added()">新增</el-button>
          <!-- <el-button type="primary" size="mini" @click="addOrEdit(1)">新增</el-button> -->
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 表单 -->
    <el-card class="box-card mt20">
      <div slot="header" class="clearfix">
        <el-button  style="float: left;" type="primary" @click="exportExcelSelect" size="mini">导出</el-button>
      </div>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        size="mini"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          prop="spec_num"
          label="编号"
          align="center"
          width="170"
        />
        <el-table-column
          prop="site_name"
          label="站点"
          align="center"
          width="150"
        />
        <el-table-column
          prop="plan_title"
          label="计划标题"
          align="center"
          width="170"
        />
        <el-table-column
          :show-overflow-tooltip="true"
          prop="plan_content"
          label="计划内容"
          align="center"
        />
        <el-table-column
          :show-overflow-tooltip="true"
          prop="plan_cycle_string"
          label="计划周期"
          align="center"
          width="70"
        />
        <el-table-column
          prop="plan_start"
          label="开始时间"
          align="center"
          width="120"
        />
        <el-table-column
          prop="plan_end"
          label="结束时间"
          align="center"
          width="120"
        />
        <el-table-column
          prop="user_name"
          label="创建人"
          align="center"
          width="100"
        />
        <el-table-column
          prop="updated_at"
          label="创建时间"
          align="center"
          width="160"
        />
        <el-table-column
          prop="right"
          label="附件"
          align="center"
          width="100"
        >
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleClick(scope.row.id)">查看</el-button>
          </template>
        </el-table-column>
          <el-table-column
          label="操作"
          align="center"
          show-overflow-tooltip
        >
          <template slot-scope="scope">

            <el-button
              size="mini"
              type="primary"
              @click="edites(scope.row.id)"
            >修改</el-button>
            <el-button
              size="mini"
              type="primary"
             @click="dels(scope.row.id)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination style='float: right;' v-show='totals>0' :total='totals' :page.sync='currentPage' :limit.sync='pageSixe' @pagination='getMaintainList' />
    </el-card>
    <!-- 底部分页 -->
<!--    <div class="currentPage">-->
<!--      <el-pagination-->
<!--        :current-page="currentPage"-->
<!--        :page-sizes="[10, 20, 50, 100]"-->
<!--        :page-size="pageSixe"-->
<!--        layout="total, sizes, prev, pager, next, jumper"-->
<!--        :total="totals"-->
<!--        @size-change="handleSizeChange"-->
<!--        @current-change="handleCurrentChange"-->
<!--        @prev-click="handelPrevChange"-->
<!--        @next-click="handelNextChange"-->
<!--      />-->
<!--    </div>-->
    <!-- 查看附件弹框 -->
    <!-- 详情组件 -->
    <div v-if="detailFlag">
      <Detail
        :id="detailId"
        :dialog-visible="detailFlag"
        :title="detailTitle"
        @close="close"
        @confirm="confirm"
      />
    </div>
     <!-- 导出组件 -->
    <ExportFile
      ref="myChild"
      :export-excel-info="exportExcelInfo"
      :table-data="tableAllData"
      :export-excel-arry="exportExcelArry"
    />
    <!-- 新增组件 -->
    <operations-explan-added  :details="details" :titles="tits" ref="operationsExplanAdded" @getList="getList"></operations-explan-added>
  </div>
</template>
<script>
// import { planList } from '@/api/operations'


import ExportFile from '@/components/exportFile/index'
import Detail from './components/edit.vue'
import OperationsExplanAdded from '@/views/operations/experiment/explan/components/added'
import { planList ,delsPlan,detailesPlan } from '@/api/operations'

export default {
  name: 'index',
  components: {
    OperationsExplanAdded,
    Detail,
    ExportFile
  },
  data() {
    return {
      tableData: [],
      details:'',
      tits:'',
      multipleSelection: [],
      currentPage: 1,
      pageSixe: 10,
      totals: 0,
      formInline: {
        plan_type: 2,
        offset: 0,
        limit: 10,
        keyword: ''
      },
      dialogTableVisible: false,
      seeTitle: '附件列表',
      detailTitle: '新增', // 弹窗标识
      detailFlag:false,
        detailId: 0, // 修改详情id
      seeDetails: [],
       tableAllData: [], // 导出的数据
       // 导出配置数据
      exportExcelArry: [{
        prop: 'spec_num',
        label: '编号',
        formatterFlag: false
      }, {
        prop: 'site_name',
        label: '站点',
        formatterFlag: false
      }, {
        prop: 'plan_title',
        label: '计划标题',
        formatterFlag: false
      }, {
        prop: 'plan_content',
        label: '计划内容',
        formatterFlag: false
      }, {
        prop: 'plan_cycle_string',
        label: '计划周期',
        formatterFlag: false
      },
      {
        prop: 'plan_start',
        label: '开始时间',
        formatterFlag: false
      },
      {
        prop: 'plan_end',
        label: '结束时间',
        formatterFlag: false
      },
       {
        prop: 'user_name',
        label: '创建人',
        formatterFlag: false
      }, {
        prop: 'updated_at',
        label: '创建时间',
        formatterFlag: false
      }],
      // 导出excel表格id及excel名称
      exportExcelInfo: {
        excelId: 'task-table',
        excelName: '试验计划.xlsx'
      },
    }
  },

  mounted() {
    this.getMaintainList()
  },
  // maintainAdd
  methods: {
    // 获取保修列表
    getMaintainList() {
      // this.formInline.offset = this.currentPage
      // this.formInline.limit = this.pageSixe
      planList(this.formInline).then(res => {
        this.tableData = res.data.plans
        this.totals = res.data.total
      })
    },
     //  关闭弹窗组件
    close() {
      this.detailFlag = false
      this.detailId = ''
    },
    // 弹窗返回
    confirm() {
      this.close()
      this.getList()
    },
    // 查看
    handleClick(a) {
      console.log('附件查看')
      this.detailTitle = '附件'
        this.detailId = a
        this.detailFlag = true
    },
    detailClosed(a) {
      this.dialogTableVisible = a
    },
    //获取接口返回的列表数据
    getList() {
      planList(this.formInline).then(res => {
        this.tableData = res.data.plans
        this.total = res.data.total
      })
    },
    // 查询
    search() {
      this.formInline.offset = 0
      this.getList()
    },
    // 导出
    exportExcelSelect() {
      if (this.multipleSelection.length === 0) {
        this.tableAllData = this.tableData
      } else {
        this.tableAllData = this.multipleSelection
      }
      // // 将选中项传给this. tableAllData
      // this.tableAllData = this.selectListArry
      // 需要延时调导出方法，为了等待数据初始化到列表中
      setTimeout(() => {
        this.$refs.myChild.exportExcel()
      }, 500)
    },
    exportExcel() {
      this.initData('export-excel')
      // 获取到表格数据的值并赋给this.tableAllData
      // 同样延时调导出方法，需在initData('export-excel')方法执行成功后调this.$refs.myChild.exportExcel();方法
    },
    // 表单选中
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleSizeChange(val) {
      this.pageSixe = val
      this.getMaintainList()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getMaintainList()
    },
    handelPrevChange(val) {
      this.currentPage = val
      this.getMaintainList()
    },
    handelNextChange(val) {
      this.currentPage = val
      this.getMaintainList()
    },
    // open(row) {
    //   this.$refs.experimentExplanEdit.open(row);
    // }
    added(row) {
         this.tits='新增'
      this.details={}
      //this.dialogVisible = true
      this.$refs.operationsExplanAdded.open(row);
    },
        // 编辑
  edites(num){
     this.tits='编辑'
    detailesPlan({id:num}).then(res=>{
      this.details=res.data
      if(this.details.length!==0){
    this.$refs.operationsExplanAdded.open();

      }

    })
  },
    // 删除
    dels(num){
       this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delsPlan({id:num}).then(res=>{
         this.getList()

      })

          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });

    },
  }
}
</script>
<style lang="scss" scoped>
.mt20{
  margin-top: 20px;
}
.formHeight{
  height: 40px;
}
.con{
  padding-left: 5px;
  padding-right: 7px;
  .top_sea{
    position: relative;
    display: flex;
    height: 35px;
    width: 400px;
    font-size: 12px;
    .seaIcon{
      position: absolute;
      top:13px;
      left:8px;
      z-index: 999;
    }
    ::v-deep.el-input__inner{
       padding-left: 25px;
    }
  }
  .fj{
    color: #409EFF;
  }
  .currentPage{
    // display: flex;
    position: fixed;
    bottom: 0;
    right: 0;
    // flex-direction: row-reverse;
    // margin-top: 20px;
  }
  .header-title{
    .seeTit{
      padding-left: 10px;
    }
  }
  //::v-deep.el-dialog__header{
  //  background-color: #263445;
  //  color: #fff;
  //}
}
</style>
